273D - Dima and Figure - CodeForces Solution


dp *2400

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=155;
const int mod=1e9+7;
int f[N][N][2][2],n,m;
signed main()
{
	cin>>n>>m;int ans=0;
	for(int i=1;i<=m;i++)for(int j=i;j<=m;j++)f[i][j][1][1]=1;
	for(int i=1;i<=n;i++)
	{
		int an=0;
		for(int l=1;l<=m;l++)for(int r=l;r<=m;r++)
		 for(int p1=0;p1<=1;p1++)for(int p2=0;p2<=1;p2++)
		  an=(an+f[l][r][p1][p2])%mod;
		ans=(ans+an*(n-i+1)%mod)%mod;
		for(int l=1;l<=m;l++)for(int r=l+1;r<=m;r++)for(int p=0;p<=1;p++)
		 f[l+1][r][0][p]=(f[l+1][r][0][p]+f[l][r][0][p]+f[l][r][1][p])%mod;
		for(int l=1;l<=m;l++)for(int r=m;r>l;r--)for(int p=0;p<=1;p++)
		 f[l][r-1][p][0]=(f[l][r-1][p][0]+f[l][r][p][1]+f[l][r][p][0])%mod;	
		for(int l=m;l>1;l--)for(int r=l;r<=m;r++)for(int p=0;p<=1;p++)
		 f[l-1][r][1][p]=(f[l-1][r][1][p]+f[l][r][1][p])%mod;
		for(int l=m;l>=1;l--)for(int r=l;r<m;r++)for(int p=0;p<=1;p++)
		 f[l][r+1][p][1]=(f[l][r+1][p][1]+f[l][r][p][1])%mod;
	}
	cout<<ans<<endl;
	return 0;
}	


Comments

Submit
0 Comments
More Questions

One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String